package com.cn.application;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author ：yuanrenmao
 * @date ：2022/3/28 12:11 PM
 * @description ：
 * 自定义ClassPathXmlApplicationContext ，重写initPropertySources方法
 */
public class MyClassPathXmlApplicationContext  extends ClassPathXmlApplicationContext {

	public MyClassPathXmlApplicationContext(String... configLocations){
		super(configLocations);
	}

	@Override
	protected void initPropertySources() {
		System.out.println("initPropertySources调用～");
		// 设置必须的属性 abc，后面会去校验
		getEnvironment().setRequiredProperties("abc");
	}

	/**
	 * 自定义配置BeanFactory
	 * @param beanFactory the newly created bean factory for this context
	 */
	@Override
	protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
		super.setAllowBeanDefinitionOverriding(false);
		super.setAllowCircularReferences(false);
		super.customizeBeanFactory(beanFactory);
	}
}
